#include "predialog.h"
#include "ui_predialog.h"

PreDialog::PreDialog(QWidget *parent) :
    QWidget(parent),
    di(new Ui::PreDialog)
{
    di->setupUi(this);
    QObject::connect(di->closeButton, SIGNAL(clicked()), this, SLOT(CloseEventHandler()));
    QObject::connect(di->clearButton_2, SIGNAL(clicked()), this, SLOT(ClearEventHandler2()));
    QObject::connect(di->postButton_2, SIGNAL(clicked()), this, SLOT(PostEventHandler2()));
}

PreDialog::~PreDialog()
{
    delete di;
}

void PreDialog::View(QByteArray text)
{
    QTextCodec* codec = QTextCodec::codecForName("UTF-8");
    QTextCodec::setCodecForTr(codec);

    di->postPreView->setHtml(tr(text));
    this->show();
}

void PreDialog::CloseEventHandler()
{
    this->hide();
}

void PreDialog::PostEventHandler2()
{
    emit post();
    this->hide();
}

void PreDialog::ClearEventHandler2()
{
    emit clear();
    this->hide();
}

void PreDialog::changeEvent(QEvent *e)
{
    QWidget::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        di->retranslateUi(this);
        break;
    default:
        break;
    }
}
